package com.lin.controller.Admin;

import com.lin.mapper.DishMapper;
import com.lin.pojo.Dish;
import com.lin.response.CommonResp;
import com.lin.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.swing.plaf.basic.ComboPopup;

@RestController
@RequestMapping("/admin")
public class PopularityController {

    @Autowired
    private DishService dishService;

    @GetMapping("/popularity")
    public CommonResp echarts(@RequestParam Integer type){
        return dishService.echarts(type);
    }

    @PostMapping("/save")
    public CommonResp save(@RequestBody Dish dish){
        dishService.saveOrUpdate(dish);
        CommonResp<String> commonResp = new CommonResp<>();
        commonResp.setMessage("新增或修改菜品信息成功。");
        commonResp.setSuccess(true);
        commonResp.setContent(null);
        return commonResp;
    }

    @PostMapping("/delete")
    public CommonResp delete(@RequestBody Dish dish){
        System.out.println(dishService.removeById(dish));
        return null;
    }
}
